package one.four.twentySeven;

public class QueueWithTwoStacks<Item> {

	private Stack<Item> one;
	private Stack<Item> two;

	public QueueWithTwoStacks() {
		one = new Stack<Item>();
		two = new Stack<Item>();
	}

	public void enqueue(Item item) {
		one.push(item);
	}

	public Item dequeue() {
		if (two.isEmpty()) {
			while (!one.isEmpty()) {
				two.push(one.pop());
			}
		}
		return two.pop();
	}

	public static void main(String[] args) {
		QueueWithTwoStacks<String> q = new QueueWithTwoStacks<String>();
		q.enqueue("a");
		q.enqueue("b");
		q.enqueue("c");

		System.out.println(q.dequeue());

		q.enqueue("d");
		q.enqueue("e");
		System.out.println(q.dequeue());
		System.out.println(q.dequeue());
		
		System.out.println(q.dequeue());
	}

}
